from django.contrib import admin

from server.apps.accounts.models import CustomUser

@admin.register(CustomUser)
class CustomUserAdmin(admin.ModelAdmin):
    def has_add_permission(self, request, obj=None):
        if request.user.is_superuser:
            return True
    
    def get_readonly_fields(self, request, obj=None):
        if not request.user.is_superuser:
            return ['is_staff', 'is_superuser']
        else:
            return []
    
    list_display = ('email', 'is_staff', 'is_superuser','is_active')

    def get_queryset(self, request):
        qs = super().get_queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(email=request.user)